package org.example.myleet.p784;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<String> letterCasePermutation(String s) {
        List<String> result = new ArrayList<>();
        backtrack(result, s.toCharArray(), 0);
        return result;
    }

    private void backtrack(List<String> result, char[] charArr, int cursor) {
        //结束递归条件
        if (cursor > charArr.length) {
            return;
        }
        if (cursor == charArr.length) {
            result.add(new String(charArr));
            return;
        }
        char c = charArr[cursor];
        if (Character.isDigit(c)) {
            //数字不用区分大小写，就一种情况
            backtrack(result, charArr, cursor + 1);
        } else {
            //字母区分大小写，各遍历一种情况
            charArr[cursor] = Character.toLowerCase(c);
            backtrack(result, charArr, cursor + 1);
            charArr[cursor] = Character.toUpperCase(c);
            backtrack(result, charArr, cursor + 1);
        }
    }
}
